#!/user/bin/python
# -*- coding:utf-8 -*-


import json
import time
import calendar
# number2 = int(input('请输入第一个数字'))
# number1 = int(input('请输入第二个数字'))
# print('100+200',number1 + number2)
# 发送psot请求登录
import requests
import unittest
import requests
def a(*aaa):
    for x in aaa:
        print(x)
    return x
def https_post():
    pararms = {'admin_UserName':'zy','admin_Password':'123456'}
    # aa = {"admin_UserName":"zhangyan","admin_Password":"123456"}
    data = json.dumps(pararms,separators=(',',':')).encode("utf-8")
    print(data)
    # print('dumps方法返回的类型是' + type(json.dumps(pararms)))
    headers = {'Content-Type': 'application/json',
            'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36",
            }
    req = requests.post('https://cert.ccpbox.com/Api/Admin/LoginRequestToken',data=data,headers=headers,verify=False)
    print("返回值的类型", type(req.content), req.content)
    res = req.content.decode("utf8")
    print("返回值的类型", type(res),res)
    return res
class MyTest(unittest.TestCase):
    def setUp(self):
        """每个用例执行前执行"""
    def test_login(self):
        res = https_post()
        resJson = json.loads(res)
        print(len(resJson["data"]["subItems"]))
        self.assertEqual(True,resJson['success'])
    def test_json_res(self):
        pararms = {'admin_UserName': 'zhangyan', 'admin_Password': '123456'}
        for key in pararms:
            print(key+":"+pararms[key])
        # dict_aa = json.dumps(pararms)
        # print(type(json.dumps(pararms).encode('utf8')))
        # print(type(dict_aa))
        # print(type(json.loads(dict_aa)))
        # self.assertEqual(True,json.loads(dict_aa)['success'])
    def test_upload(self):
        files = {'file':open("D:/NewRetail_1.18.0.apk",'rb'),}
        data = {'version':'1.18.0'}
        req = requests.post("https://cert.ccpbox.com/Files/APKVersionSave",data=data,files=files,verify=False)
        res = req.content.decode("utf-8")
        self.assertEqual(True,json.loads(res)["success"])

# url = "https://www.ccpbox.com//Api/Admin/LoginRequestToken"
# params = {
#     'admin_UserName':'zhangyan',
#     'admin_Password':'123456',
# }
# data = urllib.parse.urlencode(params).encode('utf-8')
# data1 = json.dumps(params).encode('utf-8')
# head = {'Content-Type':'application/json',
#                 'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36",
# }
# print(data1)
# req = urllib.request.Request(url,data=data1,headers=head)
# res = urllib.request.urlopen(req)
# print(res.read().decode('utf8'))
# for x in 'aaa':
#     print(x)
